home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / spaceout < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  24.7 KB

  1. From: jpochma@polyslo.UUCP (John Hoyt Pochmara)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i056: spaceout - X11 animated space display
  4. Message-ID: <7239@ncoast.UUCP>
  5. Date: 18 Feb 88 02:31:47 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 56
  9. Submitted-By: "John Hoyt Pochmara" <jpochma@polyslo.UUCP>
  10. Archive-Name: spaceout
  11.  
  12. [I didn't disappear... you did.  Where are the submissions?  ++bsa]
  13.  
  14. #! /bin/sh
  15. # This is a shell archive, meaning:
  16. # 1. Remove everything above the #! /bin/sh line.
  17. # 2. Save the resulting text in a file.
  18. # 3. Execute the file with /bin/sh (not csh) to create the files:
  19. #    README
  20. #    spaceout.6
  21. #    Makefile
  22. #    spaceout.c
  23. # This archive created: Sun Feb 14 19:22:43 1988
  24. export PATH; PATH=/bin:$PATH
  25. echo shar: extracting "'README'" '(1957 characters)'
  26. if test -f 'README'
  27. then
  28.     echo shar: will not over-write existing file "'README'"
  29. else
  30. sed 's/^    X//' << \SHAR_EOF > 'README'
  31.     X
  32.     X        README for Spaceout
  33.     X            Version 1.1
  34.     X              2/14/88
  35.     X
  36.     XWhat is Spaceout:
  37.     X        Spaceout - animated space display
  38.     X
  39.     X    Spaceout is an X11 version of the program for Xerox XDE
  40.     X    workstations.  The Xerox workstation version was done by Jef
  41.     X    Poskanzer at Versatec, A Xerox company.  Spaceout displays a
  42.     X    star field, which moves as if you were traveling through
  43.     X    space ( similar to the beginning of old Star Trek tv shows).
  44.     X
  45.     XHow To Compile:
  46.     X    If you have X11 installed on your machine in the
  47.     X    'standard' place all you should have to do is say
  48.     X    'make'. Otherwise you will have to edit the makefile
  49.     X    to point where it is all kept.
  50.     X
  51.     XTo 'Stipple' or not 'Stipple':
  52.     X    There are two ways in which Spaceout will draw the stars on the
  53.     X    screen.  Spaceout will either use stippling or copyarea to
  54.     X    draw the stars. One is of which is most likely faster on
  55.     X    you X server.  I suggest you try both and see.
  56.     X    Now how to tell Spaceout which one to use.  If 'STIPPLE_DRAW'
  57.     X    is defined then Spaceout use stippling, other wise
  58.     X    copyarea is used ( this define can be found near the top
  59.     X    of the spaceout.c ).
  60.     X
  61.     XThings To Try:
  62.     X    If you get really bored one night you might want to try playing 
  63.     X    with the parameter defines at the top of spaceout.c .
  64.     X    
  65.     X    
  66.     XHow Color works:
  67.     X    Spaceout has 6 arrays of color names in it. Spaceout
  68.     X    uses one color out of each array if the -C options is used.
  69.     X    The color names in the arrays can be a legal name for
  70.     X    XAllocNamedColor().  If the chosen color can not be allocated
  71.     X    then white is used.
  72.     X
  73.     XWhat Happens when Covered:
  74.     X    If Spaceout becomes fully obscured or iconifed it stops and
  75.     X    waits to become visible or un-iconified.
  76.     X
  77.     XWho to Bitch At:
  78.     X    If you get really stuck, you can always send mail
  79.     X    to me at
  80.     X        jpochma@polyslo.UUCP
  81.     X
  82.     X    But I make no promises ( still in school :-) ...
  83.     X    
  84.     X
  85.     XMore Copyright Info:
  86.     X        Copyright (c) 1988, John H. Pochmara
  87.     X
  88.     X    You may copy Spaceout in whole or in part as long as you don't
  89.     X    try to make money off it, or pretend that you wrote it.
  90. SHAR_EOF
  91. if test 1957 -ne "`wc -c < 'README'`"
  92. then
  93.     echo shar: error transmitting "'README'" '(should have been 1957 characters)'
  94. fi
  95. fi # end of overwriting check
  96. echo shar: extracting "'spaceout.6'" '(1190 characters)'
  97. if test -f 'spaceout.6'
  98. then
  99.     echo shar: will not over-write existing file "'spaceout.6'"
  100. else
  101. sed 's/^    X//' << \SHAR_EOF > 'spaceout.6'
  102.     X.TH SPACEOUT l "January 17, 1988"
  103.     X.UC 4
  104.     X.SH NAME
  105.     Xspaceout \- animated space display
  106.     X.SH SYNOPSIS
  107.     Xspaceout [ \-fRrCc ] [ host:display ]
  108.     X.SH DESCRIPTION
  109.     X.PP
  110.     X.IR Spaceout
  111.     Xis an X11 version of the program for Xerox XDE workstations.
  112.     XThe Xerox workstation version was done by Jef Poskanzer at
  113.     XVersatec, A Xerox company.
  114.     XSpaceout displays a star field, which moves as if you were
  115.     Xtraveling through
  116.     Xspace ( similar to the beginning of old Star Trek tv shows ).
  117.     X.PP
  118.     X.IR Spaceout
  119.     Xoptions include:
  120.     X.TP
  121.     X.B \-f
  122.     Xtries to fill the entire screen.
  123.     X.TP
  124.     X.B \-r
  125.     X\'reverse video\'.
  126.     X.TP
  127.     X.B \-R
  128.     Xruns in root window.
  129.     X.TP
  130.     X.B \-C
  131.     XColor Spaceout.
  132.     X.TP
  133.     X.B \-c
  134.     XThe stars move down the middle of the screen.
  135.     X.PP
  136.     XIf a host is not specify the environment variable DISPLAY is used.
  137.     X.PP
  138.     XAt this time I would like to express many thanks to Paul Shupak 
  139.     Xfor his comments and suggestions. He also wrote the random number generator
  140.     Xthat is used
  141.     Xin
  142.     X.IR Spaceout .
  143.     X.SH GIVE AWAY INFO
  144.     X.PP
  145.     XCopyright (c) 1988, John H. Pochmara
  146.     X.PP
  147.     XYou may copy Spaceout in whole or in part as long as you don't
  148.     Xtry to make money off it, or pretend that you wrote it.
  149.     X
  150.     X.SH FILES
  151.     X/usr/lib/X11/rgb*
  152.     X.SH AUTHOR
  153.     XJohn H. Pochmara
  154.     X.br
  155.     Xjpochma@polyslo.UUCP
  156. SHAR_EOF
  157. if test 1190 -ne "`wc -c < 'spaceout.6'`"
  158. then
  159.     echo shar: error transmitting "'spaceout.6'" '(should have been 1190 characters)'
  160. fi
  161. fi # end of overwriting check
  162. echo shar: extracting "'Makefile'" '(336 characters)'
  163. if test -f 'Makefile'
  164. then
  165.     echo shar: will not over-write existing file "'Makefile'"
  166. else
  167. sed 's/^    X//' << \SHAR_EOF > 'Makefile'
  168.     X#
  169.     X# Makefile for Spaceout Version 1.1
  170.     X# 2/14/88
  171.     X#
  172.     X# Copyright (c) 1988, John H. Pochmara
  173.     X# 
  174.     X# You may copy Spaceout in whole or in part as long as you don't
  175.     X# try to make money off it, or pretend that you wrote it.
  176.     X# 
  177.     X
  178.     XLIBS= -lX11
  179.     XSCR = spaceout.c 
  180.     XOBJ = spaceout.o 
  181.     XCFLAGS = -O -c 
  182.     X
  183.     Xspace:    $(OBJ)
  184.     X    cc -o space $(OBJ) $(LIBS)
  185.     X
  186.     X$(OBJ):    
  187. SHAR_EOF
  188. if test 336 -ne "`wc -c < 'Makefile'`"
  189. then
  190.     echo shar: error transmitting "'Makefile'" '(should have been 336 characters)'
  191. fi
  192. fi # end of overwriting check
  193. echo shar: extracting "'spaceout.c'" '(17559 characters)'
  194. if test -f 'spaceout.c'
  195. then
  196.     echo shar: will not over-write existing file "'spaceout.c'"
  197. else
  198. sed 's/^    X//' << \SHAR_EOF > 'spaceout.c'
  199.     X/*
  200.     X *
  201.     X * SpaceOut for X11. 
  202.     X * Version 1.1
  203.     X *
  204.     X * By John Pochmara (jpochma@polyslo)
  205.     X * at Cal Poly
  206.     X * 1988  
  207.     X * 
  208.     X * Random number generator writen by Pual Shupak.
  209.     X *
  210.     X * Copyright (c) 1988, John H. Pochmara
  211.     X * 
  212.     X * You may copy Spaceout in whole or in part as long as you don't
  213.     X * try to make money off it, or pretend that you wrote it.
  214.     X * 
  215.     X *
  216.     X * Original SpaceOut writen in Mesa for Xerox workstations by
  217.     X * Jef Poskanzer at Versatec, a Xerox Company.
  218.     X *
  219.     X * 
  220.     X * Options:
  221.     X *    R - run in root window.
  222.     X *    r - reverse screen.
  223.     X *    f - full screen.
  224.     X *    c - all stars go right down the center of the screen.
  225.     X *     C - Color Space.
  226.     X *
  227.     X */
  228.     X
  229.     X#include <stdio.h>
  230.     X#include <X11/Xlib.h>
  231.     X#include <X11/Xatom.h>
  232.     X#include <X11/Xutil.h>
  233.     X
  234.     X#define STIPPLE_DRAW
  235.     X
  236.     X#define NUM_STARS    (70)        /* Number of Stars */
  237.     X#define STAR_MAXSIZE    (400)        /* Max size of Stars */
  238.     X#define SPEEDZ        (270)        /* Speed at which Stars move forward */
  239.     X#define MIN_VISIBLEZ    (400)        /* Closets you can get to a star */
  240.     X#define MAX_VISIBLEZ    (65000)        /* Farthest away star you can see */
  241.     X#define MINX        (-20000)    /* Min value of X cordanit */
  242.     X#define MAXX        (20000)        /* Max value of X cordanit */
  243.     X#define MINY        (-20000)    /* Min value of Y cordanit */
  244.     X#define MAXY        (20000)        /* Max value of Y cordanit */
  245.     X#define MINZ        (30000)        /* Min value of Z cordanit */
  246.     X#define MAXZ        (65535)        /* Max value of Z cordanit */
  247.     X#define SCREENZ        (1500)        /* Distance of projected image */
  248.     X#define RADIUS        (40)        /* Size of a Star at SCREENZ */
  249.     X#define MAG_RAD        (1)        /* Magnification factor of Star Radius */
  250.     X
  251.     X#define TRUE        (1)
  252.     X#define FALSE        (0)
  253.     X
  254.     X#define RNDRANGE( min, max ) \
  255.     X( ( ( (max) - (min) ) ? ( randomLong() % ( (max) - (min) ) ) : 0 ) + (min) )
  256.     X
  257.     X#define OBSCURED    (1)
  258.     X#define UNOBSCURED    (0)
  259.     X
  260.     X/*
  261.     X * Star Types.
  262.     X */
  263.     X#define ROUND        (0)
  264.     X#define RINGED        (1)
  265.     X#define PLANETX        (2)
  266.     X
  267.     X/*
  268.     X * Init. Window Postion & Dimension.
  269.     X */
  270.     X#define INT_WIDTH    (400)
  271.     X#define INT_HEIGHT    (250)
  272.     X#define INT_X        (50)
  273.     X#define INT_Y        (50)
  274.     X
  275.     X
  276.     X#define WHITE        (0)
  277.     X#define COLOR1        (1)
  278.     X#define COLOR2        (2)
  279.     X#define COLOR3        (3)
  280.     X#define COLOR4        (4)
  281.     X#define COLOR5         (5)
  282.     X#define COLOR6        (6)
  283.     X
  284.     Xchar *color1[] = {
  285.     X        "pink",
  286.     X        "plum",
  287.     X        "red",
  288.     X        "IndianRed",
  289.     X        "MediumVioletRed",
  290.     X        "OrangeRed",
  291.     X        "VioletRed",
  292.     X        ""
  293.     X};
  294.     X
  295.     Xchar *color2[] = {
  296.     X        "Green",
  297.     X        "DarkGreen",
  298.     X        "DarkOliveGreen",
  299.     X        "ForestGreen",
  300.     X        "LimeGreen",
  301.     X        "MediumForestGreen",
  302.     X        "MediumSeaGreen",
  303.     X        "MediumSpringGreen",
  304.     X        "PaleGreen",
  305.     X        "SeaGreen",
  306.     X        "SpringGreen",
  307.     X        "YellowGreen",
  308.     X        ""
  309.     X};
  310.     X
  311.     Xchar *color3[] = {
  312.     X        "Blue",
  313.     X        "CadetBlue",
  314.     X        "CornflowerBlue",
  315.     X        "DarkSlateBlue",
  316.     X        "LightBlue",
  317.     X        "LightSteelBlue",
  318.     X        "MediumBlue",
  319.     X        "MediumSlateBlue",
  320.     X        "MidnightBlue",
  321.     X        "NavyBlue",
  322.     X        "Navy",
  323.     X        "SkyBlue",
  324.     X        "SlateBlue",
  325.     X        "SteelBlue",
  326.     X        ""
  327.     X};
  328.     X
  329.     Xchar *color4[] = {
  330.     X        "Yellow",
  331.     X        "GreenYellow",
  332.     X        "Wheat",
  333.     X        "Turquoise",
  334.     X        "Sienna",
  335.     X        ""
  336.     X};
  337.     X
  338.     Xchar *color5[] = {
  339.     X        "orange",
  340.     X        "Khaki",
  341.     X        "Maroon",
  342.     X        "Orchid",
  343.     X        ""
  344.     X};
  345.     X
  346.     Xchar *color6[] = {
  347.     X        "violet",
  348.     X        "BlueViolet",
  349.     X        "Salmon",
  350.     X        "Gold",
  351.     X        "Goldenrod",
  352.     X        "Coral",
  353.     X        ""
  354.     X};
  355.     X
  356.     X#define MAX_USED_COLORS ( 7 )
  357.     X
  358.     XXColor starColors[MAX_USED_COLORS];
  359.     X
  360.     Xtypedef struct starrec {
  361.     X    int sx,sy;
  362.     X    int x,y,z;
  363.     X    int radius;
  364.     X    int displayed;
  365.     X    int type;
  366.     X    int color;
  367.     X} StarRec;
  368.     X
  369.     XStarRec Stars[NUM_STARS];
  370.     X
  371.     XPixmap Starpix[STAR_MAXSIZE];
  372.     XPixmap Ringpix[STAR_MAXSIZE];
  373.     XPixmap Xpix[STAR_MAXSIZE];
  374.     XDisplay *dpy;
  375.     XWindow SpaceWin;
  376.     XWindow root;
  377.     XWindow parent;
  378.     XColormap cmap;
  379.     Xint screen;
  380.     Xint depth;
  381.     Xint SpaceVis;
  382.     X
  383.     X/*
  384.     X * Option Var.
  385.     X *
  386.     X */
  387.     Xint rootwin = FALSE;
  388.     Xint fullscreen = FALSE;
  389.     Xint reverse = FALSE;
  390.     Xint color = FALSE;
  391.     Xint center = FALSE;
  392.     Xchar *host = NULL;
  393.     X
  394.     Xint winwidth;
  395.     Xint winheight;
  396.     Xint winx;
  397.     Xint winy;
  398.     X
  399.     Xstatic void init(), initwin(), initpos(), initpix(), initstar();
  400.     Xstatic void initcolors(), setcolor();
  401.     Xstatic void MoveStars(), DisplayStar(), NewStar(), ShowStar();
  402.     Xstatic void DrawStar(), Newpixmap(), ProcEvent(), ReDrawStars();
  403.     Xstatic void ReStart(), ClearStars(), usage(), prev();
  404.     Xstatic unsigned long int randomLong();
  405.     X
  406.     Xmain(argc,argv)
  407.     Xint argc;
  408.     Xchar *argv[];
  409.     X{
  410.     X
  411.     X    while(--argc > 0) {
  412.     X        if(index(argv[argc],':') != 0) {
  413.     X            if(host != NULL)
  414.     X                usage();
  415.     X            else
  416.     X                host = argv[argc];
  417.     X        } else if(argv[argc][0] == '-') {
  418.     X            int i = 1;
  419.     X            
  420.     X            while(argv[argc][i] != NULL) {
  421.     X                switch(argv[argc][i]) {
  422.     X                    case 'f': fullscreen = TRUE;
  423.     X                          break;
  424.     X                    case 'r': reverse = TRUE;
  425.     X                          break;
  426.     X                    case 'c': center = TRUE;
  427.     X                          break;
  428.     X                    case 'C': color = TRUE;
  429.     X                          break;
  430.     X                    case 'R': rootwin = TRUE;
  431.     X                          break;
  432.     X                    default:  usage();
  433.     X                }
  434.     X                i++;
  435.     X            }
  436.     X        }
  437.     X    }
  438.     X
  439.     X    if(host == NULL) {
  440.     X        if((host = (char *) getenv("DISPLAY")) == NULL) {
  441.     X            usage();
  442.     X        }
  443.     X    }
  444.     X
  445.     X    init(host);
  446.     X    MoveStars(Stars);
  447.     X
  448.     X}
  449.     X
  450.     Xstatic void init(host)
  451.     Xchar *host;
  452.     X{
  453.     X
  454.     X    initwin(host);
  455.     X    srandom((int) time(0));
  456.     X    initstar();
  457.     X    initpix();
  458.     X
  459.     X    SpaceVis = UNOBSCURED;
  460.     X
  461.     X}
  462.     X
  463.     Xstatic void MoveStars(stars)
  464.     XStarRec stars[];
  465.     X{
  466.     X    int i;
  467.     X
  468.     X    while(TRUE) {
  469.     X        ProcEvent();
  470.     X        for(i=0;i<NUM_STARS;i++) {
  471.     X            if(stars[i].z > SPEEDZ) {
  472.     X                stars[i].z = stars[i].z - SPEEDZ;
  473.     X            } else {
  474.     X                stars[i].z = MIN_VISIBLEZ/2;
  475.     X            }
  476.     X
  477.     X            DisplayStar(&stars[i]);
  478.     X        }
  479.     X        XFlush(dpy);
  480.     X
  481.     X    }
  482.     X
  483.     X}
  484.     X
  485.     Xstatic void DisplayStar(star)
  486.     XStarRec *star;
  487.     X{
  488.     X    int scrx;
  489.     X    int scry;
  490.     X    int scrradius;
  491.     X
  492.     X
  493.     X    if(star->z <= 0 ) star->z = 1;
  494.     X
  495.     X    scrx = (star->x * SCREENZ) / star->z;
  496.     X    scry = (star->y * SCREENZ) / star->z;
  497.     X    scrradius = (RADIUS * SCREENZ) / star->z;
  498.     X
  499.     X    scrx = (winwidth/2 + scrx);
  500.     X    scry = (winheight/2 + scry);
  501.     X
  502.     X    if((scrx == star->sx)
  503.     X        && (scry == star->sy) 
  504.     X        && ( scrradius == star->radius ))
  505.     X            return;
  506.     X
  507.     X    if(star->z < MIN_VISIBLEZ) {
  508.     X        if(star->displayed == TRUE) {
  509.     X            ShowStar(star);
  510.     X            star->displayed = FALSE;
  511.     X        }
  512.     X        NewStar(star);
  513.     X        return;
  514.     X    }
  515.     X
  516.     X    if(star->z > MAX_VISIBLEZ) {
  517.     X        if(star->displayed == TRUE) {
  518.     X            ShowStar(star);
  519.     X            star->displayed = FALSE;
  520.     X        }
  521.     X        return;
  522.     X    }
  523.     X
  524.     X    if(star->displayed == TRUE) {
  525.     X        ShowStar(star);
  526.     X        star->displayed = FALSE;
  527.     X    }
  528.     X
  529.     X    if((scrx > winwidth) || (scrx < -(2 * star->radius)) ||
  530.     X       (scry > winheight) || (scry < -(2 * star->radius))) {
  531.     X        NewStar(star);
  532.     X        return;
  533.     X    }
  534.     X
  535.     X    star->sx = scrx;
  536.     X    star->sy = scry;
  537.     X    star->radius = scrradius;
  538.     X
  539.     X    ShowStar(star);
  540.     X    star->displayed = TRUE;
  541.     X
  542.     X}
  543.     X
  544.     Xstatic void NewStar(star)
  545.     XStarRec *star;
  546.     X{
  547.     X    int rnd = RNDRANGE(0,100);
  548.     X    int x_range, y_range;
  549.     X
  550.     X    star->z = RNDRANGE(MINZ,MAXZ);
  551.     X
  552.     X    if(center != TRUE) {
  553.     X        x_range = (star->z * winwidth) / ( 2 * SCREENZ);
  554.     X        y_range = (star->z * winheight) / (2 * SCREENZ);
  555.     X
  556.     X        star->x = RNDRANGE(-(x_range),x_range);
  557.     X        star->y = RNDRANGE(-(y_range),y_range);
  558.     X    } else {
  559.     X        star->x = 0; 
  560.     X        star->y = 0;
  561.     X    }
  562.     X
  563.     X    star->sx = (star->x * SCREENZ) / star->z;
  564.     X    star->sy = (star->y * SCREENZ) / star->z;
  565.     X    star->radius = (RADIUS * SCREENZ) / star->z;
  566.     X    star->displayed = FALSE;
  567.     X    star->color = WHITE;
  568.     X
  569.     X    if(rnd < 3)
  570.     X        star->type = PLANETX;
  571.     X    else if(rnd < 10)
  572.     X        star->type = RINGED;
  573.     X    else {
  574.     X        star->type = ROUND;
  575.     X        star->color = RNDRANGE(0, MAX_USED_COLORS - 1);
  576.     X    }
  577.     X
  578.     X}
  579.     X
  580.     Xstatic void ShowStar(star)
  581.     XStarRec *star;
  582.     X{
  583.     X
  584.     X    if(star->radius <= 0) 
  585.     X        star->radius = 1;
  586.     X
  587.     X    if(star->radius > STAR_MAXSIZE) 
  588.     X        star->radius = STAR_MAXSIZE;
  589.     X
  590.     X    switch(star->type) {
  591.     X        case RINGED:
  592.     X            if(Ringpix[star->radius] == 0) Newpixmap(star);
  593.     X            break;
  594.     X        case ROUND:
  595.     X            if(Starpix[star->radius] == 0) Newpixmap(star);
  596.     X            break;
  597.     X        case PLANETX:
  598.     X            if(Xpix[star->radius] == 0) Newpixmap(star);
  599.     X            break;
  600.     X    }
  601.     X
  602.     X    DrawStar(star);
  603.     X
  604.     X}
  605.     X
  606.     Xstatic void DrawStar(star)
  607.     XStarRec *star;
  608.     X{
  609.     X    static GC gc[MAX_USED_COLORS] = { 0 };
  610.     X    int p_width = 2 * ((star->radius) * MAG_RAD);
  611.     X    int p_height = 2 * ((star->radius) * MAG_RAD);
  612.     X    Pixmap drawpix;
  613.     X    GC stargc;
  614.     X    int sx,sy;
  615.     X    int i;
  616.     X
  617.     X    if(gc[0] == 0) {
  618.     X
  619.     X        for(i = 0; i < MAX_USED_COLORS; i++) {
  620.     X            gc[i] = XCreateGC(dpy,SpaceWin,0,NULL);
  621.     X            XSetFunction(dpy,gc[i],GXxor);
  622.     X            XSetBackground(dpy,gc[i],BlackPixel(dpy,screen));
  623.     X            if( color == TRUE ) 
  624.     X                XSetForeground(dpy,gc[i],starColors[i].pixel);
  625.     X            else
  626.     X                XSetForeground(dpy,gc[i],WhitePixel(dpy,screen));
  627.     X#ifdef STIPPLE_DRAW
  628.     X            XSetFillStyle(dpy,gc[i],FillStippled);
  629.     X#else
  630.     X            XSetGraphicsExposures(dpy,gc[i],FALSE);
  631.     X#endif STIPPLE_DRAW
  632.     X        }
  633.     X    }
  634.     X
  635.     X    stargc = gc[star->color];
  636.     X
  637.     X    switch(star->type) {
  638.     X        case ROUND:
  639.     X            drawpix = Starpix[star->radius];
  640.     X            break;
  641.     X        case RINGED:
  642.     X            drawpix = Ringpix[star->radius];
  643.     X            p_width *= 2;
  644.     X            break;
  645.     X        case PLANETX:
  646.     X            drawpix = Xpix[star->radius];
  647.     X            break;
  648.     X        default:
  649.     X            drawpix = Starpix[star->radius];
  650.     X            break;
  651.     X            
  652.     X    }
  653.     X            
  654.     X    sx = star->sx - p_width/2;
  655.     X    sy = star->sy - p_height/2;
  656.     X
  657.     X#ifdef STIPPLE_DRAW
  658.     X    XSetStipple(dpy,stargc,drawpix);
  659.     X    XSetTSOrigin(dpy,stargc,sx,sy);
  660.     X    XFillRectangle(dpy,SpaceWin,stargc,sx,sy,p_width,p_height);
  661.     X#else
  662.     X    XCopyArea(dpy,drawpix,SpaceWin,stargc,0,0,p_width,p_height,sx,sy);
  663.     X#endif STIPPLE_DRAW
  664.     X
  665.     X}
  666.     X
  667.     Xstatic void Newpixmap(star)
  668.     XStarRec *star;
  669.     X{
  670.     X    static GC gc = 0;
  671.     X    Pixmap pixtmp;
  672.     X    int i;
  673.     X    int p_width = 2 * ((star->radius) * MAG_RAD);
  674.     X    int p_height = 2 * ((star->radius) * MAG_RAD);
  675.     X    int r = star->radius;
  676.     X
  677.     X    if(star->type == RINGED) {
  678.     X        p_width = 2 * p_width;
  679.     X    }
  680.     X
  681.     X#ifdef STIPPLE_DRAW
  682.     X    pixtmp = XCreatePixmap(dpy,SpaceWin,p_width,p_height,1);
  683.     X#else
  684.     X    pixtmp = XCreatePixmap(dpy,SpaceWin,p_width,p_height,depth);
  685.     X#endif STIPPLE_DRAW
  686.     X
  687.     X    if(gc == 0) {
  688.     X        gc = XCreateGC(dpy,pixtmp,0,NULL);
  689.     X        XSetBackground(dpy,gc,BlackPixel(dpy,screen));
  690.     X        XSetForeground(dpy,gc,WhitePixel(dpy,screen));
  691.     X        XSetFillStyle(dpy,gc,FillSolid);
  692.     X    }
  693.     X
  694.     X    switch(star->type) {
  695.     X        case ROUND:
  696.     X            XSetFunction(dpy,gc,GXxor);
  697.     X            XFillArc(dpy,pixtmp,gc,0,0,p_width,p_height,0,360*64);
  698.     X            Starpix[star->radius] = pixtmp;
  699.     X            break;
  700.     X        case RINGED:
  701.     X            XSetFunction(dpy,gc,GXxor);
  702.     X            XSetLineAttributes(dpy,gc,1,LineSolid,CapRound,JoinBevel);
  703.     X            XFillArc(dpy,pixtmp,gc,r,0,p_height,p_height,0,360*64);
  704.     X            XDrawArc(dpy,pixtmp,gc,0,r/2,p_width,p_height/2,
  705.     X                0,360*64);
  706.     X            Ringpix[star->radius] = pixtmp;
  707.     X            break;
  708.     X        case PLANETX:
  709.     X            XSetFunction(dpy,gc,GXxor);
  710.     X            XFillArc(dpy,pixtmp,gc,0,0,p_width,p_height,0,360*64);
  711.     X            i = r/4;
  712.     X            if(i < 1) i = 1;
  713.     X            XSetLineAttributes(dpy,gc,i,LineSolid,CapRound,JoinBevel);
  714.     X            XSetFunction(dpy,gc,GXclear);
  715.     X            XDrawLine(dpy,pixtmp,gc,r/2,r/2,r+r/2,r+r/2);
  716.     X            XDrawLine(dpy,pixtmp,gc,r+r/2,r/2,r/2,r+r/2);
  717.     X            Xpix[star->radius] = pixtmp;
  718.     X            break;
  719.     X    }
  720.     X
  721.     X}
  722.     X
  723.     Xstatic void initstar()
  724.     X{
  725.     X    int i;
  726.     X
  727.     X    for(i=0;i<NUM_STARS;i++) {
  728.     X        NewStar(&Stars[i]);
  729.     X    }
  730.     X
  731.     X}
  732.     X
  733.     Xstatic void initpix()
  734.     X{
  735.     X    int i;
  736.     X
  737.     X    for(i=0;i<STAR_MAXSIZE;i++) {
  738.     X        Starpix[i] = 0;
  739.     X        Ringpix[i] = 0;
  740.     X        Xpix[i] = 0;
  741.     X    }
  742.     X}
  743.     X
  744.     Xstatic void initpos()
  745.     X{
  746.     X    if(fullscreen == TRUE) {
  747.     X        winwidth = XDisplayWidth(dpy,screen);
  748.     X        winheight = XDisplayHeight(dpy,screen);
  749.     X        winx = 0;
  750.     X        winy = 0;
  751.     X    } else {
  752.     X        winwidth = INT_WIDTH;
  753.     X        winheight = INT_HEIGHT;
  754.     X        winx = INT_X;
  755.     X        winy = INT_Y;
  756.     X    }
  757.     X}
  758.     X
  759.     Xextern int XCheckTypedEvent();
  760.     X
  761.     Xstatic void ProcEvent()
  762.     X{
  763.     X    XEvent ev;
  764.     X    int block = FALSE;
  765.     X    
  766.     X    while((XPending(dpy) > 0) || (block == TRUE)) {
  767.     X        XNextEvent(dpy,&ev);
  768.     X        switch(ev.type) {
  769.     X            case ReparentNotify:
  770.     X                if(ev.xreparent.window != SpaceWin ) break;
  771.     X                XSelectInput(dpy,ev.xreparent.parent,
  772.     X                    StructureNotifyMask);
  773.     X                XSelectInput(dpy,parent,0);
  774.     X                parent = ev.xreparent.parent;
  775.     X                break;
  776.     X
  777.     X            case UnmapNotify:
  778.     X                if((ev.xunmap.window != SpaceWin) &&
  779.     X                   (ev.xunmap.window != parent)) break;
  780.     X                block = TRUE;
  781.     X                break;
  782.     X                    
  783.     X            case VisibilityNotify:
  784.     X                if(ev.xvisibility.window != SpaceWin) break;
  785.     X                if(ev.xvisibility.state == 
  786.     X                     VisibilityFullyObscured) {
  787.     X                    block = TRUE;
  788.     X                    break;
  789.     X                }
  790.     X                if((ev.xvisibility.state == 
  791.     X                      VisibilityUnobscured) && 
  792.     X                      (SpaceVis == OBSCURED)) {
  793.     X                    ReStart();
  794.     X                    SpaceVis = UNOBSCURED;
  795.     X                    block = FALSE;
  796.     X                    break;
  797.     X                }
  798.     X                if(ev.xvisibility.state == 
  799.     X                     VisibilityPartiallyObscured) {
  800.     X                    SpaceVis = OBSCURED;
  801.     X                    block = FALSE;
  802.     X                }
  803.     X                break;
  804.     X                            
  805.     X            case Expose:
  806.     X                ReStart();
  807.     X                block = FALSE;
  808.     X                break;
  809.     X
  810.     X            case MapNotify:
  811.     X                if((ev.xmap.window != SpaceWin) &&
  812.     X                   (ev.xmap.window != parent)) break;
  813.     X                ReStart();
  814.     X                block = FALSE;
  815.     X                break;
  816.     X
  817.     X            case ConfigureNotify:
  818.     X                if(ev.xconfigure.window != SpaceWin) break;
  819.     X                ReStart();
  820.     X                if((winwidth == ev.xconfigure.width) && 
  821.     X                   (winheight == ev.xconfigure.height))
  822.     X                    break;
  823.     X                winwidth = ev.xconfigure.width;
  824.     X                winheight = ev.xconfigure.height;
  825.     X                ReDrawStars();
  826.     X                block = FALSE;
  827.     X                break;
  828.     X
  829.     X            default:
  830.     X                break;
  831.     X        }
  832.     X    }
  833.     X}
  834.     X
  835.     Xstatic void ReDrawStars()
  836.     X{
  837.     X    int i;
  838.     X
  839.     X    for(i=0;i<NUM_STARS;i++) {
  840.     X        DisplayStar(&Stars[i]);
  841.     X    }
  842.     X}
  843.     X
  844.     Xstatic void ReStart()
  845.     X{
  846.     X    XClearWindow(dpy,SpaceWin);
  847.     X    XSync(dpy, 0);
  848.     X    ClearStars();
  849.     X}
  850.     X
  851.     Xstatic void ClearStars()
  852.     X{
  853.     X    int i;
  854.     X
  855.     X    for(i=0;i<NUM_STARS;i++) {
  856.     X        Stars[i].displayed = FALSE;
  857.     X    }
  858.     X}
  859.     X
  860.     Xstatic void initcolors()
  861.     X{
  862.     X    unsigned long backgrd;
  863.     X
  864.     X    if( reverse == TRUE )
  865.     X        backgrd = WhitePixel(dpy,screen);
  866.     X    else
  867.     X        backgrd = BlackPixel(dpy,screen);
  868.     X
  869.     X    starColors[WHITE].pixel = WhitePixel(dpy,screen);
  870.     X
  871.     X    setcolor(color1,&starColors[COLOR1]);
  872.     X    starColors[COLOR1].pixel ^= backgrd;
  873.     X
  874.     X    setcolor(color2,&starColors[COLOR2]);
  875.     X    starColors[COLOR2].pixel ^= backgrd;
  876.     X
  877.     X    setcolor(color3,&starColors[COLOR3]);
  878.     X    starColors[COLOR3].pixel ^= backgrd;
  879.     X
  880.     X    setcolor(color4,&starColors[COLOR4]);
  881.     X    starColors[COLOR4].pixel ^= backgrd;
  882.     X
  883.     X    setcolor(color5,&starColors[COLOR5]);
  884.     X    starColors[COLOR5].pixel ^= backgrd;
  885.     X
  886.     X    setcolor(color6,&starColors[COLOR6]);
  887.     X    starColors[COLOR6].pixel ^= backgrd;
  888.     X
  889.     X
  890.     X}
  891.     X
  892.     Xstatic void setcolor(cnames,xcolor)
  893.     Xchar *cnames[];
  894.     XXColor *xcolor;
  895.     X{
  896.     X    int i = 0;
  897.     X    int count = 0;
  898.     X    XColor ecolor;
  899.     X
  900.     X    while( *cnames[count] != NULL ) {
  901.     X         count++;
  902.     X    }
  903.     X
  904.     X    i = RNDRANGE(0,count-1);
  905.     X
  906.     X    if( XAllocNamedColor(dpy,cmap,cnames[i],xcolor,&ecolor) > 0) 
  907.     X        return;
  908.     X    else {
  909.     X        i = 0;
  910.     X
  911.     X        while( *cnames[i] != NULL ) {
  912.     X            if( XAllocNamedColor(dpy,cmap,cnames[i],
  913.     X                        xcolor,&ecolor) > 0) 
  914.     X                return;
  915.     X            else
  916.     X                continue;
  917.     X        }
  918.     X    }
  919.     X    
  920.     X    xcolor->pixel = starColors[WHITE].pixel;
  921.     X}
  922.     X
  923.     Xstatic void initwin(hostmon)
  924.     Xchar *hostmon;
  925.     X{
  926.     X    XSetWindowAttributes attr;
  927.     X    char *name;
  928.     X
  929.     X    if((dpy = XOpenDisplay(hostmon)) == NULL) {
  930.     X        fprintf(stderr,"Connection not made.\n");
  931.     X        exit(1);
  932.     X    }
  933.     X
  934.     X    screen = DefaultScreen(dpy);
  935.     X    cmap = DefaultColormap(dpy,screen);
  936.     X    parent = root = RootWindow(dpy,screen);
  937.     X    depth = DefaultDepth(dpy,screen);
  938.     X
  939.     X    if( color == TRUE ) 
  940.     X        initcolors();
  941.     X
  942.     X    initpos();
  943.     X
  944.     X    XSelectInput(dpy,root,SubstructureNotifyMask);
  945.     X
  946.     X    attr.event_mask = StructureNotifyMask
  947.     X            | SubstructureNotifyMask
  948.     X            | VisibilityChangeMask
  949.     X            | ExposureMask;
  950.     X
  951.     X    if(reverse == TRUE) 
  952.     X        attr.background_pixel = WhitePixel(dpy,screen);
  953.     X    else
  954.     X        attr.background_pixel = BlackPixel(dpy,screen);
  955.     X
  956.     X    if(rootwin == TRUE) {
  957.     X        SpaceWin = root;
  958.     X        XChangeWindowAttributes(dpy,SpaceWin,
  959.     X                    CWEventMask|CWBackPixel,&attr);
  960.     X    } else {
  961.     X
  962.     X        SpaceWin = XCreateWindow(dpy,root,winx,winy,winwidth,winheight,
  963.     X                    0,depth,InputOutput,
  964.     X                    DefaultVisual(dpy,screen),
  965.     X                    CWEventMask|CWBackPixel,&attr);
  966.     X
  967.     X        if( color == TRUE )
  968.     X            name = "Color SpaceOut";
  969.     X        else
  970.     X            name = "SpaceOut";
  971.     X
  972.     X        XChangeProperty(dpy,SpaceWin,XA_WM_NAME,XA_STRING,8,
  973.     X            PropModeReplace,name,strlen(name));
  974.     X        XMapWindow(dpy,SpaceWin);
  975.     X    }
  976.     X
  977.     X    XClearWindow(dpy,SpaceWin);
  978.     X    XSync(dpy, 0);
  979.     X
  980.     X}
  981.     X
  982.     Xstatic void usage()
  983.     X{
  984.     X    fprintf(stderr,"usage: space [host:screen] [-frCc]\n");
  985.     X    exit(0);
  986.     X}
  987.     X
  988.     Xstatic int randomBit()
  989.     X{
  990.     Xregister unsigned long int tmp ;
  991.     Xstatic unsigned long int state = 0x10 ;
  992.     X
  993.     X/* Linear Feedback Shift Register
  994.     X * Length = 31 Bits
  995.     X * Taps at 3 & 31
  996.     X * Period = ( 2 ** 31 ) - 1
  997.     X */
  998.     Xtmp = state ;
  999.     X/* Next State */
  1000.     Xstate = ( ( ( tmp << 2 ) ^ ( tmp << 30 ) ) & 0x80000000 ) | ( tmp >> 1 ) ;
  1001.     X
  1002.     Xreturn tmp >> 31 ;
  1003.     X}
  1004.     X
  1005.     X/* Random Number Generator State Variables */
  1006.     Xstatic unsigned long int lastRandom = 1 ;
  1007.     Xstatic unsigned long int oldRandom ;
  1008.     X
  1009.     Xstatic unsigned long int randomLong()
  1010.     X{
  1011.     Xregister unsigned long int tmpA ;
  1012.     Xregister unsigned long int tmpB ;
  1013.     X
  1014.     Xregister unsigned long int tmpH ;
  1015.     Xregister unsigned long int tmpM1 ;
  1016.     Xregister unsigned long int tmpM2 ;
  1017.     Xregister unsigned long int tmpL ;
  1018.     X
  1019.     Xregister long int SumOldL ;
  1020.     Xregister long int SumOldH ;
  1021.     Xregister long int SumLastL ;
  1022.     Xregister long int SumLastH ;
  1023.     X
  1024.     X/*
  1025.     X * Modular Congruence Method
  1026.     X * Period >= ( 2 ** 31 ) - 1
  1027.     X * X(n) =
  1028.     X *   ( 271,828,183 * X(n-1) - 314,159,269 * X(n-2) ) mod ( ( 2 ** 31 ) - 1 )
  1029.     X * = (  0x1033C4D7 * X(n-1) -  0x12B9B0A5 * X(n-2) ) mod ( ( 2 ** 31 ) - 1 )
  1030.     X * To Avoid OverFlow USE:
  1031.     X *    ( ( x1 * ( 2 ** 16 ) ) + x2 ) * ( ( y1 * ( 2 ** 15 ) ) + y2 ) =
  1032.     X *           ( x1 * y1 * ( 2 ** 31 ) )
  1033.     X *         + ( x2 * y1 * ( 2 ** 15 ) )
  1034.     X *         + ( x1 * y2 * ( 2 ** 16 ) )
  1035.     X *         + ( x2 * y2  )
  1036.     X * NOTE:
  1037.     X * 0x1033C4D7 == ( 0x2067 * 0x08000 ) + 0x44D7
  1038.     X *            == ( 0x1033 * 0x10000 ) + 0xC4D7
  1039.     X * 0x12B9B0A5 == ( 0x2573 * 0x08000 ) + 0x30A5
  1040.     X *            == ( 0x12B9 * 0x10000 ) + 0xB0A5
  1041.     X */
  1042.     XtmpA   = oldRandom ;
  1043.     X
  1044.     XtmpB   = tmpA & 0xFFFF ;    /* Low Order 16 Bits of X(n-2) */
  1045.     XtmpM1  = tmpB * 0x2573 ;    /* Offset 16 Bits */
  1046.     XtmpL   = tmpB * 0x30A5 ;    /* Offset  0 Bits */
  1047.     XtmpA   >>= 16 ;            /* High Order 15 Bits of X(n-2)
  1048.     XtmpH   = tmpA * 0x2573 ;    /* Offset 31 Bits */
  1049.     XtmpM2  = tmpA * 0x30A5 ;    /* Offset 15 Bits */
  1050.     X/* Now Sum Them */
  1051.     XSumOldL  = tmpL & 0x7FFF ;
  1052.     XtmpA     = ( tmpL >> 15 ) + tmpM2 + ( tmpM1 << 1 ) ;
  1053.     XSumOldL |= ( ( tmpA << 15 ) & 0x7FFF8000 ) ;    /* Bottom 31 Bits */
  1054.     XSumOldH  = ( ( tmpA >> 16 ) + tmpH ) ;        /* Top 31 Bits */
  1055.     X
  1056.     XoldRandom = tmpA = lastRandom ;
  1057.     X
  1058.     XtmpB   = tmpA & 0xFFFF ;    /* Low Order 16 Bits of X(n-1) */
  1059.     XtmpM1  = tmpB * 0x2067 ;    /* Offset 15 bits */
  1060.     XtmpL   = tmpB * 0x44D7 ;    /* Offset  0 bits */
  1061.     XtmpA   >>= 16 ;            /* High Order 15 Bits of X(n-1)*/
  1062.     XtmpH   = tmpA * 0x2067 ;    /* Offset 31 bits */
  1063.     XtmpM2  = tmpA * 0x44D7 ;    /* Offset 16 bits */
  1064.     X/* Now Sum Them */
  1065.     XSumLastL  = tmpL & 0x7FFF ;
  1066.     XtmpA      = ( tmpL >> 15 ) + tmpM2 + ( tmpM1 << 1 ) ;
  1067.     XSumLastL |= ( ( tmpA << 15 ) & 0x7FFF8000 ) ;    /* Bottom 31 Bits */
  1068.     XSumLastH  = ( ( tmpA >> 16 ) + tmpH ) ;        /* Top 31 Bits */
  1069.     X
  1070.     XtmpA = SumLastH - SumOldH ;
  1071.     XtmpB = SumLastL - SumOldL ;
  1072.     Xif ( SumLastL < SumOldL ) {
  1073.     X    tmpB &= 0x7FFFFFFF ;
  1074.     X    tmpA-- ;
  1075.     X}
  1076.     X
  1077.     Xreturn lastRandom = ( ( tmpA + tmpB ) & 0x7FFFFFFF ) ;
  1078.     X}
  1079.     X
  1080.     Xstatic void prev(ev)
  1081.     XXEvent *ev;
  1082.     X{
  1083.     X    printf("event->type: %d\n",ev->type);
  1084.     X}
  1085. SHAR_EOF
  1086. if test 17559 -ne "`wc -c < 'spaceout.c'`"
  1087. then
  1088.     echo shar: error transmitting "'spaceout.c'" '(should have been 17559 characters)'
  1089. fi
  1090. fi # end of overwriting check
  1091. #    End of shell archive
  1092. exit 0
  1093.